package com.topInterview;

import java.util.*;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/20 14:08
 */
public class leecode49 {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String tmp = String.valueOf(chars);
            if (!map.containsKey(tmp)) {
                map.put(tmp,new ArrayList());
            }
            map.get(tmp).add(str);
        }
        List<List<String>> res = new ArrayList<>();
        for (List<String> value :map.values()) {
            res.add(value);
        }


        return res;
    }
}
